home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / Kubuntu 8.10 / kubuntu-8.10-desktop-i386.iso / casper / filesystem.squashfs / usr / lib / openoffice / program / senddoc < prev    next >
Text File  |  2008-10-15  |  8KB  |  413 lines

  1. #!/bin/sh
  2. URI_ENCODE="`dirname $0`/uri-encode"
  3.  
  4.  
  5. # tries to locate the executable specified 
  6. # as first parameter in the user's path.
  7. which() {
  8.     if [ ! -z "$1" ]; then
  9.         for i in `echo $PATH | sed -e 's/^:/.:/g' -e 's/:$/:./g' -e 's/::/:.:/g' -e 's/:/ /g'`; do
  10.             if [ -x "$i/$1" -a ! -d "$i/$1" ]; then
  11.                 echo "$i/$1"
  12.                 break;
  13.             fi
  14.         done
  15.     fi
  16. }
  17.  
  18. # checks for the original mozilla start script(s) 
  19. # and restrict the "-remote" semantics to those.
  20. run_mozilla() {
  21.     # find mozilla script in PATH if necessary
  22.     if [ "`basename $1`" = "$1" ]; then
  23.         moz=`which $1`
  24.     else
  25.         moz=$1
  26.     fi
  27.  
  28.     if file -L "$moz" | grep "script" > /dev/null && grep "[NM]PL" "$moz" > /dev/null; then
  29.         "$moz" -remote 'ping()' 2>/dev/null >/dev/null
  30.         if [ $? -eq 2 ]; then
  31.             "$1" -compose "$2" &
  32.         else
  33.             "$1" -remote "xfeDoCommand(composeMessage,$2)" &
  34.         fi
  35.     else
  36.         "$1" -compose "$2" &
  37.     fi
  38. }
  39.  
  40. # restore search path for dynamic loader to system defaults to
  41. # avoid version clashes of mozilla libraries shipped with OOo
  42. case `uname -s` in
  43.     AIX)
  44.         LIBPATH=$SYSTEM_LIBPATH
  45.         if [ -z "$LIBPATH" ]; then
  46.             unset LIBPATH SYSTEM_LIBPATH
  47.         else
  48.             export LIBPATH; unset SYSTEM_LIBPATH
  49.         fi
  50.         ;;
  51.  
  52.     Darwin)
  53.         DYLD_LIBRARY_PATH=$SYSTEM_DYLD_LIBRARY_PATH
  54.         if [ -z "$DYLD_LIBRARY_PATH" ]; then
  55.             unset DYLD_LIBRARY_PATH SYSTEM_DYLD_LIBRARY_PATH
  56.         else
  57.             export DYLD_LIBRARY_PATH; unset SYSTEM_DYLD_LIBRARY_PATH
  58.         fi
  59.         ;;
  60.  
  61.     HP-UX)
  62.         SHLIB_PATH=$SYSTEM_SHLIB_PATH
  63.         if [ -z "$SHLIB_PATH" ]; then
  64.             unset SHLIB_PATH SYSTEM_SHLIB_PATH
  65.         else
  66.             export SHLIB_PATH; unset SYSTEM_SHLIB_PATH
  67.         fi
  68.         ;;
  69.  
  70.     IRIX*)
  71.         LD_LIBRARYN32_PATH=$SYSTEM_LD_LIBRARYN32_PATH
  72.         if [ -z "$LD_LIBRARYN32_PATH" ]; then
  73.             unset LD_LIBRARYN32_PATH SYSTEM_LD_LIBRARYN32_PATH
  74.         else
  75.             export LD_LIBRARYN32_PATH; unset $SYSTEM_LD_LIBRARYN32_PATH
  76.         fi
  77.         ;;
  78.  
  79.     *)
  80.         LD_LIBRARY_PATH=$SYSTEM_LD_LIBRARY_PATH
  81.         if [ -z "$LD_LIBRARY_PATH" ]; then
  82.             unset LD_LIBRARY_PATH SYSTEM_LD_LIBRARY_PATH
  83.         else
  84.             export LD_LIBRARY_PATH; unset SYSTEM_LD_LIBRARY_PATH
  85.         fi
  86.         ;;
  87. esac
  88.  
  89. if [ "$1" = "--mailclient" ]; then
  90.     shift
  91.     MAILER=$1
  92.     shift
  93. fi
  94.  
  95. case `basename "$MAILER"` in
  96.     sensible-ooomua)
  97.         if [ -n "$GNOME_DESKTOP_SESSION_ID" -a -x /usr/bin/evolution ]; then
  98.             MAILER=/usr/bin/evolution
  99.         elif [ -n "$KDE_FULL_SESSION" -a -x /usr/bin/kmail ]; then
  100.             MAILER=/usr/bin/kmail
  101.         elif [ -x /usr/bin/evolution ]; then
  102.             # default
  103.             MAILER=/usr/bin/evolution
  104.         fi
  105.         ;;
  106. esac
  107.  
  108. # autodetect mail client from executable name
  109. case `basename "$MAILER" | sed 's/-.*$//'` in
  110.  
  111.     iceape | mozilla | netscape | seamonkey | icedove | thunderbird)
  112.     
  113.         while [ "$1" != "" ]; do
  114.             case $1 in
  115.                 --to)
  116.                     TO=${TO:-}${TO:+,}$2
  117.                     shift
  118.                     ;;
  119.                 --cc)
  120.                     CC=${CC:-}${CC:+,}$2
  121.                     shift
  122.                     ;;
  123.                 --bcc)
  124.                     BCC=${BCC:-}${BCC:+,}$2
  125.                     shift
  126.                     ;;
  127.                 --subject)
  128.                     SUBJECT=$2
  129.                     shift
  130.                     ;;
  131.                 --body)
  132.                     BODY=$2
  133.                     shift
  134.                     ;;
  135.                 --attach)
  136.                     ATTACH=${ATTACH:-}${ATTACH:+,}`echo "file://$2" | ${URI_ENCODE}`
  137.                     shift
  138.                     ;;
  139.                 *)
  140.                     ;;
  141.             esac
  142.             shift;
  143.         done
  144.  
  145.         if [ "$TO" != "" ]; then
  146.             COMMAND=${COMMAND:-}${COMMAND:+,}to=${TO}
  147.         fi
  148.         if [ "$CC" != "" ]; then
  149.             COMMAND=${COMMAND:-}${COMMAND:+,}cc=${CC}
  150.         fi
  151.         if [ "$BCC" != "" ]; then
  152.             COMMAND=${COMMAND:-}${COMMAND:+,}bcc=${BCC}
  153.         fi
  154.         if [ "$SUBJECT" != "" ]; then
  155.             COMMAND=${COMMAND:-}${COMMAND:+,}subject=${SUBJECT}
  156.         fi
  157.         if [ "$BODY" != "" ]; then
  158.             COMMAND=${COMMAND:-}${COMMAND:+,}body=${BODY}
  159.         fi
  160.         if [ "$ATTACH" != "" ]; then
  161.             COMMAND=${COMMAND:-}${COMMAND:+,}attachment=${ATTACH}
  162.         fi
  163.         
  164.         run_mozilla "$MAILER" "$COMMAND"
  165.         ;;
  166.         
  167.     kmail)
  168.     
  169.         while [ "$1" != "" ]; do
  170.             case $1 in
  171.                 --to)
  172.                     TO="${TO:-}${TO:+,}$2"
  173.                     shift
  174.                     ;;
  175.                 --cc)
  176.                     CC="${CC:-}${CC:+,}$2"
  177.                     shift
  178.                     ;;
  179.                 --bcc)
  180.                     BCC="${BCC:-}${BCC:+,}$2"
  181.                     shift
  182.                     ;;
  183.                 --subject)
  184.                     SUBJECT="$2"
  185.                     shift
  186.                     ;;
  187.                 --body)
  188.                     BODY="$2"
  189.                     shift
  190.                     ;;
  191.                 --attach)
  192.                     ATTACH="$2"
  193.                     shift
  194.                     ;;
  195.                 *)
  196.                     ;;
  197.             esac
  198.             shift;
  199.         done
  200.         
  201.         ${MAILER} --composer ${CC:+--cc} ${CC:+"${CC}"} ${BCC:+--bcc} ${BCC:+"${BCC}"} \
  202.             ${SUBJECT:+--subject} ${SUBJECT:+"${SUBJECT}"} ${BODY:+--body} ${BODY:+"${BODY}"} \
  203.             ${ATTACH:+--attach} ${ATTACH:+"${ATTACH}"} ${TO:+"${TO}"}
  204.         ;;
  205.         
  206.     mutt)
  207.     
  208.         while [ "$1" != "" ]; do
  209.             case $1 in
  210.                 --from)
  211.                     FROM="$2"
  212.                     shift
  213.                     ;;
  214.                 --to)
  215.                     TO="${TO:-}${TO:+,}$2"
  216.                     shift
  217.                     ;;
  218.                 --cc)
  219.                     CC="${CC:-}${CC:+,}$2"
  220.                     shift
  221.                     ;;
  222.                 --bcc)
  223.                     BCC="${BCC:-}${BCC:+,}$2"
  224.                     shift
  225.                     ;;
  226.                 --subject)
  227.                     SUBJECT="$2"
  228.                     shift
  229.                     ;;
  230.                 --body)
  231.                     TEMPLATE="`basename $0`.mutt.XXXXXXXX"
  232.                     BODY=`mktemp -q -t ${TEMPLATE}`
  233.                     echo "$2" > $BODY
  234.                     shift
  235.                     ;;
  236.                 --attach)
  237.                     ATTACH="$2"
  238.                     shift
  239.                     ;;
  240.                 *)
  241.                     ;;
  242.             esac
  243.             shift;
  244.         done
  245.         
  246.         x-terminal-emulator -e ${MAILER} \
  247.             ${FROM:+-e} ${FROM:+"set from=\"${FROM}\""} \
  248.             ${CC:+-c} ${CC:+"${CC}"} \
  249.             ${BCC:+-b} ${BCC:+"${BCC}"} \
  250.             ${SUBJECT:+-s} ${SUBJECT:+"${SUBJECT}"} \
  251.             ${BODY:+-i} ${BODY:+"${BODY}"} \
  252.             ${ATTACH:+-a} ${ATTACH:+"${ATTACH}"} \
  253.             ${TO:+"${TO}"} &
  254.         rm -f $BODY
  255.         ;;
  256.         
  257.     evolution | groupwise)
  258.     
  259.         while [ "$1" != "" ]; do
  260.             case $1 in
  261.                 --to)
  262.                     if [ "${TO}" != "" ]; then
  263.                         MAILTO="${MAILTO:-}${MAILTO:+&}to=$2"
  264.                     else
  265.                         TO="$2"
  266.                     fi
  267.                     shift
  268.                     ;;
  269.                 --cc)
  270.                     MAILTO="${MAILTO:-}${MAILTO:+&}cc="`echo "$2" | ${URI_ENCODE}`
  271.                     shift
  272.                     ;;
  273.                 --bcc)
  274.                     MAILTO="${MAILTO:-}${MAILTO:+&}bcc="`echo "$2" | ${URI_ENCODE}`
  275.                     shift
  276.                     ;;
  277.                 --subject)
  278.                     MAILTO="${MAILTO:-}${MAILTO:+&}subject"=`echo "$2" | ${URI_ENCODE}`
  279.                     shift
  280.                     ;;
  281.                 --body)
  282.                     MAILTO="${MAILTO:-}${MAILTO:+&}body="`echo "$2" | ${URI_ENCODE}`
  283.                     shift
  284.                     ;;
  285.                 --attach)
  286.                     MAILTO="${MAILTO:-}${MAILTO:+&}attachment="`echo "file://$2" | ${URI_ENCODE}`
  287.                     shift
  288.                     ;;
  289.                 *)
  290.                     ;;
  291.             esac
  292.             shift;
  293.         done
  294.         
  295.         MAILTO="mailto:${TO}?${MAILTO}"
  296.         ${MAILER} "${MAILTO}" &
  297.         ;;
  298.  
  299.     dtmail)
  300.      
  301.         while [ "$1" != "" ]; do
  302.             case $1 in
  303.                 --to)
  304.                     TO=${TO:-}${TO:+,}$2
  305.                     shift
  306.                     ;;
  307.                 --attach)
  308.                     ATTACH="$2"
  309.                     shift
  310.                     ;;
  311.                 *)
  312.                     ;;
  313.             esac
  314.             shift;
  315.         done
  316.          
  317.         ${MAILER} ${TO:+-T} ${TO:-} ${ATTACH:+-a} ${ATTACH:+"${ATTACH}"}
  318.         ;;
  319.  
  320.     sylpheed)
  321.      
  322.         while [ "$1" != "" ]; do
  323.             case $1 in
  324.                 --to)
  325.                     TO=${TO:-}${TO:+,}$2
  326.                     shift
  327.                     ;;
  328.                 --attach)
  329.                     ATTACH="${ATTACH:-}${ATTACH:+ }$2"
  330.                     shift
  331.                     ;;
  332.                 *)
  333.                     ;;
  334.             esac
  335.             shift;
  336.         done
  337.          
  338.          ${MAILER} ${TO:+--compose} "${TO:-}" ${ATTACH:+--attach} "${ATTACH:-}"
  339.         ;;
  340.  
  341.     Mail | Thunderbird | *.app )
  342.  
  343.         while [ "$1" != "" ]; do
  344.             case $1 in
  345.                 --attach)
  346.                     ATTACH="${ATTACH:-}${ATTACH:+ } $2"
  347.                     shift
  348.                     ;;
  349.                 *)
  350.                     ;;
  351.             esac
  352.             shift;
  353.         done
  354.          
  355.         /usr/bin/open -a "${MAILER}" ${ATTACH}
  356.         ;;
  357.  
  358.     "")
  359.     
  360.         # DESKTOP_LAUNCH, see http://freedesktop.org/pipermail/xdg/2004-August/004489.html
  361.         if [ -n "$DESKTOP_LAUNCH" ]; then
  362.             while [ "$1" != "" ]; do
  363.                 case $1 in
  364.                     --to)
  365.                         if [ "${TO}" != "" ]; then
  366.                             MAILTO="${MAILTO:-}${MAILTO:+&}to=$2"
  367.                         else
  368.                             TO="$2"
  369.                         fi
  370.                         shift
  371.                         ;;
  372.                     --cc)
  373.                         MAILTO="${MAILTO:-}${MAILTO:+&}cc="`echo "$2" | ${URI_ENCODE}`
  374.                         shift
  375.                         ;;
  376.                     --bcc)
  377.                         MAILTO="${MAILTO:-}${MAILTO:+&}bcc="`echo "$2" | ${URI_ENCODE}`
  378.                         shift
  379.                         ;;
  380.                     --subject)
  381.                         MAILTO="${MAILTO:-}${MAILTO:+&}subject="`echo "$2" | ${URI_ENCODE}`
  382.                         shift
  383.                         ;;
  384.                     --body)
  385.                         MAILTO="${MAILTO:-}${MAILTO:+&}body="`echo "$2" | ${URI_ENCODE}`
  386.                         shift
  387.                         ;;
  388.                     --attach)
  389.                         MAILTO="${MAILTO:-}${MAILTO:+&}attachment="`echo "$2" | ${URI_ENCODE}`
  390.                         shift
  391.                         ;;
  392.                     *)
  393.                         ;;
  394.                 esac
  395.                 shift;
  396.             done
  397.         
  398.             MAILTO="mailto:${TO}?${MAILTO}"
  399.             ${DESKTOP_LAUNCH} "${MAILTO}" &
  400.         else
  401.             echo "Could not determine a mail client to use."
  402.             exit 2
  403.         fi
  404.         ;;
  405.         
  406.     *)
  407.         echo "Unsupported mail client: `basename $MAILER | sed 's/-.*^//'`"
  408.         exit 2
  409.         ;;
  410. esac  
  411.   
  412. exit 0
  413.